package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Manager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

/**
 * @program: DormitoryManager
 * @description: 显示宿管细节
 * @author: ShuangChenYue
 * @create: 2021-05-19 09:07
 **/
@WebServlet(value="/ViewDormManagerDetail")
public class ViewDormManagerDetailServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("进入了宿舍管理员细节");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>显示超管细节</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-manager/superManagerDetail.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Dorm Manager</h1>");
        out.println("</div>");
        out.println("<div id=\"div01\">");
        out.println("<h3 class=\"ListName\">yours</h3>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>密码</td>");
        out.println("<td>权限</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        Manager dormManager = (Manager) req.getSession().getAttribute("dormManager");
        out.println("<tr class=\"tr02\">");
        out.println("<td style=\"text-align: center\">"+dormManager.getId()+"</td>");
        out.println("<td>"+dormManager.getName()+"</td>");
        out.println("<td>"+dormManager.getPassword()+"</td>");
        out.println("<td>"+dormManager.getStatus()+"</td>");
        out.println("<td><a href=\"/DormitoryManager/mvc/toUpdateDMDetail.do?id="+dormManager.getId()+"\" target=\"_blank\"><i class=\"iconfontU alterIcon\" title=\"修改\">&#xe700;</i></a>");
        out.println("</tr>");
        out.println("</table>");
        out.println("<h3 class=\"ListName\">others</h3>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>权限</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        List<Manager> allCommonManagerList = (List<Manager>) req.getSession().getAttribute("allCommonManagerList");
        Iterator<Manager> iterator = allCommonManagerList.iterator();
        while (iterator.hasNext())
        {
            Manager manager = iterator.next();
            if (manager.getName().equals (dormManager.getName()))
            {
                System.out.println("值相等");
            }else {
                out.println("<tr class=\"tr02\">");
                out.println("<td style=\"text-align: center\">"+manager.getId()+"</td>");
                out.println("<td>"+manager.getName()+"</td>");
                out.println("<td>"+manager.getStatus()+"</td>");
                out.println("<td><i id=\"no\" class=\"iconfontU\" title=\"无操作权限\">&#xea79;</i></td>");
                out.println("</tr>");
            }

        }
        out.println("</table>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
